﻿using System;
using System.IO;
using System.Xml.Serialization;
using System.Data;
using System.Xml;
using System.Diagnostics;


namespace FunctionalityTests
{
    public class EventLogger
    {
        const String LOGSOURCENAME = "KaaWebRssAggregator";
        private EventLog myLog=null;

        public EventLogger()
        {
            // Create the source, if it does not already exist.
            if (!EventLog.SourceExists(LOGSOURCENAME))
            {
                //An event log source should not be created and immediately used.
                //There is a latency time to enable the source, it should be created
                //prior to executing the application that uses the source.
                //Execute this sample a second time to use the new source.
                EventLog.CreateEventSource(LOGSOURCENAME, LOGSOURCENAME);
                // The source is created.  Exit the application to allow it to be registered.
                return;
            }
            // Create an EventLog instance and assign its source.
            EventLog myLog = new EventLog();
            myLog.Source = LOGSOURCENAME;
        }

        public void sendToLog(String message)
        {
            myLog.WriteEntry(message);
        }

        public void runTest()
        {

            // Create the source, if it does not already exist.
            if (!EventLog.SourceExists("MySource"))
            {
                //An event log source should not be created and immediately used.
                //There is a latency time to enable the source, it should be created
                //prior to executing the application that uses the source.
                //Execute this sample a second time to use the new source.
                EventLog.CreateEventSource("MySource", "MyNewLog");
                Console.WriteLine("CreatedEventSource");
                Console.WriteLine("Exiting, execute the application a second time to use the source.");
                // The source is created.  Exit the application to allow it to be registered.
                return;
            }

            // Create an EventLog instance and assign its source.
            EventLog myLog = new EventLog();
            myLog.Source = "MySource";

            // Write an informational entry to the event log.    
            myLog.WriteEntry("Writing to event log.");
            Console.ReadLine();

        }
    }
}
